package br.com.sig.security.presentation.action;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

import br.com.sig.business.exception.BaseException;
import br.com.sig.presentation.action.BaseAction;
import br.com.sig.security.business.model.bo.PermissionBO;
import br.com.sig.security.business.model.entity.Permission;

@Named
@ViewScoped
public class PermissionAction extends BaseAction<Permission> {

	private static final long serialVersionUID = -1138935385561467635L;
	
	private boolean readPermission;
	private boolean writePermission;
	
	@Inject
	private PermissionBO permissionBO;

	@PostConstruct
	public void init() {
		setService(permissionBO);
	}
	
	@Override
	protected Permission createInstance() {
		Permission permission = new Permission();
		permission.setFather(new Permission());
		return permission;
	}
	
	@Override
	public void persist() throws BaseException {
		permissionBO.persist(getInstance(), readPermission, writePermission);
		afterPersist();		
	}

	public boolean isReadPermission() {
		return readPermission;
	}

	public void setReadPermission(boolean readPermission) {
		this.readPermission = readPermission;
	}

	public boolean isWritePermission() {
		return writePermission;
	}

	public void setWritePermission(boolean writePermission) {
		this.writePermission = writePermission;
	}
}